package com.wanczy.dao.proxy;

import java.sql.Connection;
import java.util.List;

import org.apache.commons.dbutils.DbUtils;

import com.wanczy.dao.MenuOpDAO;
import com.wanczy.dao.impl.MenuOpDAOImpl;
import com.wanczy.pojo.MenuTable;
import com.wanczy.util.GetDBConnection;

public class MenuOpDAOProxy implements MenuOpDAO{
	public Connection conn = null;
	public MenuOpDAOImpl impl = null;
	public MenuOpDAOProxy() {
		try {
			this.conn = GetDBConnection.getConnection();//ȡ�����ݿ������
			this.impl = new MenuOpDAOImpl(this.conn);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	@Override
	public List<MenuTable> findByMenuName(String menuName,int menuState) {
		List<MenuTable> list = this.impl.findByMenuName(menuName,menuState);
		DbUtils.closeQuietly(conn);
		return list;
	}
	@Override
	public int findCountByMenuName(int userId) {
		int count = this.impl.findCountByMenuName(userId);
		DbUtils.closeQuietly(conn);
		return count;
	}
	@Override
	public boolean doDel(int menuId) {
		boolean flag = this.impl.doDel(menuId);
		DbUtils.commitAndCloseQuietly(conn);
		return flag;
	}
	@Override
	public boolean doIns(MenuTable menuTble) {
		boolean flag = this.impl.doIns(menuTble);
		DbUtils.commitAndCloseQuietly(conn);
		return flag;
	}
	@Override
	public MenuTable findByMenuId(int menuId) {
		MenuTable menuTable = this.impl.findByMenuId(menuId);
		DbUtils.closeQuietly(conn);
		return menuTable;
	}
	
	@Override
	public List<MenuTable> findByNextMenu(String menuLevel) {
		List<MenuTable> list = this.impl.findByNextMenu(menuLevel);
		DbUtils.closeQuietly(conn);
		return list;
	}
	
	@Override
	public boolean doUpd(MenuTable menuTable) {
		boolean flag = this.impl.doUpd(menuTable);
		DbUtils.commitAndCloseQuietly(conn);
		return flag;
	}
	@Override
	public List<MenuTable> findByMenuLevel(int menuLevel) {
		List<MenuTable> list = this.impl.findByMenuLevel(menuLevel);
		DbUtils.closeQuietly(conn);
		return list;
	}
	@Override
	public String findByMenuName(String menuName) {
		String menuLevel = this.impl.findByMenuName(menuName);
		DbUtils.closeQuietly(conn);
		return menuLevel;
	}
	@Override
	public List<MenuTable> display(int userId, int pageSize, int pageCurrent,String menuName) {
		List<MenuTable> list = this.impl.display(userId, pageSize, pageCurrent,menuName);
		DbUtils.closeQuietly(conn);
		return list;
	}
}
